package com.hsc.www.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class UserController {
    @Autowired
    private ServerProperties serverProperties;


    @RequestMapping("/getUsers")
    List<User> getAll() {
        Long random = System.currentTimeMillis() % 10;


        List<User> userList = new ArrayList<>();
        for (long i = 1; i <= random; i++) {
            User user = new User();
            user.setName("张三" + i);
            user.setAge(i);
            user.setServer(serverProperties.getPort().toString());
            userList.add(user);
        }
        return userList;
    }

    @RequestMapping("/getUserByName/{name}")
    User getUserByName(@PathVariable("name") String name) {

        Long random = System.currentTimeMillis() % 10;

        User user = new User();
        user.setName(name);
        user.setAge(random);
        user.setServer(serverProperties.getPort().toString());
        return user;
    }
}
